﻿using Estsh.Core.Wms.IServices;
using Estsh.Core.Model.Result;
using Microsoft.AspNetCore.Mvc;
using Estsh.Core.Models;
using Estsh.Core.Controllers;
using Microsoft.AspNetCore.Authorization;
using Newtonsoft.Json.Linq;

namespace Estsh.Core.Web.Areas.Wms.Controllers.ERPInterface
{
    [Route("wms/[controller]")]
    [ApiController]
    public class MESInterfaceController : WmsBaseController
    {
        private IProductOffLineInterfaceService service;

        // GET: LoginController
        public MESInterfaceController(IProductOffLineInterfaceService _service)
        {
            service = _service;
        }

        #region 主数据

        /// <summary>
        /// 从SAP传递物料基本信息到WMS
        /// </summary>
        /// <param name="jobj"></param>
        /// <returns></returns>
        [HttpPost("OutPdlineMethod")]
        [AllowAnonymousAttribute]
        public IActionResult OutPdlineMethod(List<MesWmsHgOutPdlineInterface> responseData)
        {
            WmsInterfaceResult result = new WmsInterfaceResult();
            try
            {
                if (responseData == null)
                {
                    result.success = false;
                    result.message = "对象不能为空";
                    return Json(result);
                }
                else
                {
                    if (responseData.Count==0)
                    {
                        result.success = false;
                        result.message = "数据不能为空";
                        return Json(result);
                    }

                    result = service.OutPdlineMethod(responseData);
                }
            }
            catch (Exception ex)
            {
                result.success = false;
                result.message = ex.Message;
                return Json(result);
            }
            return Json(result);
        }

        #endregion

    }
}
